package com.rc.web.service.impl;


import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.rc.pojo.po.Poems;
import com.rc.web.mapper.PoemsMapper;
import com.rc.web.service.PoemsService;
import org.springframework.stereotype.Service;
import java.util.Random;

@Service
public class PoemsServiceImpl extends ServiceImpl<PoemsMapper, Poems> implements PoemsService {

    /**
     * 挑选古诗
     * @param user
     * @return
     */
    @Override
    public Poems getRandomPoem(String user) {

        if (user.contains("橘") || user.contains("柑") || user.contains("橙")) {
            //生成随机数，作为随机诗歌的序号
            Random random = new Random();
            int num = random.nextInt(15) + 1; // 生成 0-14 后加 1
            Poems poems=this.getById(num);
            return poems;
        }
        else if(user.contains("稻")){
            //生成随机数，作为随机诗歌的序号
            Random random = new Random();
            int num = random.nextInt(16, 26); // 直接指定范围
            Poems poems=this.getById(num);
            return poems;
        }
        else if(user.contains("麦")){
            //生成随机数，作为随机诗歌的序号
            Random random = new Random();
            int num = random.nextInt(26, 36); // 直接指定范围
            Poems poems=this.getById(num);
            return poems;
        }
        else{
            return null;
        }
    }
}
